package com.example.bms.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.Message;
import com.example.bms.mapper.MessageMapper;
import com.example.bms.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @apiNote 用于实现对留言的增删改查
 * @author
 * @email 3108289016@qq.com
 * @since 1.0.0
 */
@Service
@Transactional
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;


    /**
     * @apiNote 查询所有留言
     * @param page 页数
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public IPage<Message> findAll(Page page) {
        System.out.println(page+"12312");
        System.out.println(page.getRecords());
        return messageMapper.findAll(page);
    }


    /**
     * @apiNote 根据id查询留言
     * @param id 留言Id
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public Message findById(Integer id) {
        return messageMapper.findById(id);
    }


    /**
     * @apiNote 根据id删除留言
     * @param id 留言Id
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public int delete(Integer id) {
        return messageMapper.delete(id);
    }


    @Override
    public int update(Message message) {
        return messageMapper.update(message);
    }


    /**
     * @apiNote 增加留言
     * @param message 留言实体类
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public int add(Message message) {
        return messageMapper.add(message);
    }
}
